import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import CourseManage from '../views/CourseManage.vue'

const routes = [
  { path: '/', redirect: '/home' },
  { path: '/home', name: 'Home', component: Home, meta: { title: '首页' } },

  // 线索管理
  { path: '/leads/list', name: 'LeadsList', component: () => import('../views/LeadsList.vue'), meta: { title: '线索列表' } },
  { path: '/leads/pool', name: 'LeadsPool', component: () => import('../views/LeadsPool.vue'), meta: { title: '线索池' } },

  // 商机管理
  { path: '/opps/list', name: 'OppsList', component: () => import('../views/OppsList.vue'), meta: { title: '商机列表' } },
  { path: '/opps/pool', name: 'OppsPool', component: () => import('../views/OppsPool.vue'), meta: { title: '公海池' } },

  // 客户管理
  { path: '/customers', name: 'Customers', component: () => import('../views/Customers.vue'), meta: { title: '客户管理' } },

  // 资源管理
  { path: '/courses', name: 'Courses', component: CourseManage, meta: { title: '课程管理' } },
  { path: '/activities', name: 'Activities', component: () => import('../views/ActivityManage.vue'), meta: { title: '活动管理' } },

  // 系统管理
  { path: '/system/departments', name: 'Departments', component: () => import('../views/DepartmentManage.vue'), meta: { title: '部门管理' } },
  { path: '/system/roles', name: 'Roles', component: () => import('../views/RoleManage.vue'), meta: { title: '角色管理' } },
  { path: '/system/users', name: 'Users', component: () => import('../views/UserManage.vue'), meta: { title: '用户管理' } },
  { path: '/system/logs', name: 'SystemLogs', component: () => import('../views/SystemLog.vue'), meta: { title: '系统日志' } },

  { path: '/:pathMatch(.*)*', redirect: '/home' },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.afterEach((to) => {
  if (to.meta?.title) {
    document.title = `轻客管家 - ${to.meta.title}`
  }
})

export default router